///////////////////////////////////////////////////////////////////////////////////////////////////
//this file is automatically generated, do not modify.
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "test_gb2312.h"
#include <cassert>

using namespace slim;

namespace test_gb2312
{
///////////////////////////////////////////////////////////////////////////////////////////////////
void Model::read( const XmlNode* node )
{
	assert( node != NULL );

	NodeIterator iter;
	const XmlNode* childNode = NULL;
	const XmlAttribute* attribute = NULL;

	childNode = node->findChild( "Skeleton" );
	if ( childNode != NULL )
	{
		Skeleton = childNode->getValue<const Char*>();
	}

	childNode = node->findFirstChild( "Part", iter );
	while ( childNode != NULL )
	{
		Parts.resize( Parts.size() + 1 );
		Parts.back().read( childNode );
		childNode = node->findNextChild( "Part", iter );
	}

	childNode = node->findFirstChild( "Animation", iter );
	while ( childNode != NULL )
	{
		Animations.resize( Animations.size() + 1 );
		Animations.back().read( childNode );
		childNode = node->findNextChild( "Animation", iter );
	}

	childNode = node->findFirstChild( "Light", iter );
	while ( childNode != NULL )
	{
		Lights.resize( Lights.size() + 1 );
		Lights.back().read( childNode );
		childNode = node->findNextChild( "Light", iter );
	}

	childNode = node->findChild( "Window" );
	if ( childNode != NULL )
	{
		Window.read( childNode );
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void Model::write( XmlNode* node ) const
{
	assert( node != NULL );

	node->clearChild();
	node->clearAttribute();

	XmlNode* childNode = NULL;
	XmlAttribute* attribute = NULL;

	if ( Skeleton != "" )
	{
		childNode = node->addChild( "Skeleton" );
		childNode->setValue( Skeleton );
	}

	for ( std::vector<Part>::const_iterator iter = Parts.begin();
		  iter != Parts.end();
		  ++iter )
	{
		const Part& obj = *iter;
		childNode = node->addChild( "Part" );
		obj.write( childNode );
	}

	for ( std::vector<Animation>::const_iterator iter = Animations.begin();
		  iter != Animations.end();
		  ++iter )
	{
		const Animation& obj = *iter;
		childNode = node->addChild( "Animation" );
		obj.write( childNode );
	}

	for ( std::vector<Light>::const_iterator iter = Lights.begin();
		  iter != Lights.end();
		  ++iter )
	{
		const Light& obj = *iter;
		childNode = node->addChild( "Light" );
		obj.write( childNode );
	}

	childNode = node->addChild( "Window" );
	Window.write( childNode );
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void Part::read( const XmlNode* node )
{
	assert( node != NULL );

	NodeIterator iter;
	const XmlNode* childNode = NULL;
	const XmlAttribute* attribute = NULL;

	attribute = node->findAttribute( "Slot" );
	if ( attribute != NULL )
	{
		Slot = attribute->getValue<const Char*>();
	}

	attribute = node->findAttribute( "Filename" );
	if ( attribute != NULL )
	{
		Filename = attribute->getValue<const Char*>();
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void Part::write( XmlNode* node ) const
{
	assert( node != NULL );

	node->clearChild();
	node->clearAttribute();

	XmlNode* childNode = NULL;
	XmlAttribute* attribute = NULL;

	if ( Slot != "" )
	{
		attribute = node->addAttribute( "Slot", Slot.c_str() );
	}

	if ( Filename != "" )
	{
		attribute = node->addAttribute( "Filename", Filename.c_str() );
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void Animation::read( const XmlNode* node )
{
	assert( node != NULL );

	NodeIterator iter;
	const XmlNode* childNode = NULL;
	const XmlAttribute* attribute = NULL;

	attribute = node->findAttribute( "Slot" );
	if ( attribute != NULL )
	{
		Slot = attribute->getValue<const Char*>();
	}

	attribute = node->findAttribute( "Filename" );
	if ( attribute != NULL )
	{
		Filename = attribute->getValue<const Char*>();
	}

	childNode = node->findFirstChild( "Event", iter );
	while ( childNode != NULL )
	{
		Events.resize( Events.size() + 1 );
		Events.back().read( childNode );
		childNode = node->findNextChild( "Event", iter );
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void Animation::write( XmlNode* node ) const
{
	assert( node != NULL );

	node->clearChild();
	node->clearAttribute();

	XmlNode* childNode = NULL;
	XmlAttribute* attribute = NULL;

	if ( Slot != "" )
	{
		attribute = node->addAttribute( "Slot", Slot.c_str() );
	}

	if ( Filename != "" )
	{
		attribute = node->addAttribute( "Filename", Filename.c_str() );
	}

	for ( std::vector<Event>::const_iterator iter = Events.begin();
		  iter != Events.end();
		  ++iter )
	{
		const Event& obj = *iter;
		childNode = node->addChild( "Event" );
		obj.write( childNode );
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void Event::read( const XmlNode* node )
{
	assert( node != NULL );

	NodeIterator iter;
	const XmlNode* childNode = NULL;
	const XmlAttribute* attribute = NULL;

	attribute = node->findAttribute( "Time" );
	if ( attribute != NULL )
	{
		Time = attribute->getValue<float>();
	}

	attribute = node->findAttribute( "Type" );
	if ( attribute != NULL )
	{
		Type = attribute->getValue<const Char*>();
	}

	childNode = node->findFirstChild( "Param", iter );
	while ( childNode != NULL )
	{
		Params.resize( Params.size() + 1 );
		Params.back() = childNode->getValue<const Char*>();
		childNode = node->findNextChild( "Param", iter );
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void Event::write( XmlNode* node ) const
{
	assert( node != NULL );

	node->clearChild();
	node->clearAttribute();

	XmlNode* childNode = NULL;
	XmlAttribute* attribute = NULL;

	if ( Time != 0.0f )
	{
		attribute = node->addAttribute( "Time", Time );
	}

	if ( Type != "" )
	{
		attribute = node->addAttribute( "Type", Type.c_str() );
	}

	for ( std::vector<std::string>::const_iterator iter = Params.begin();
		  iter != Params.end();
		  ++iter )
	{
		const std::string& value = *iter;
		childNode = node->addChild( "Param" );
		childNode->setValue( value );
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void Light::read( const XmlNode* node )
{
	assert( node != NULL );

	NodeIterator iter;
	const XmlNode* childNode = NULL;
	const XmlAttribute* attribute = NULL;

	childNode = node->findChild( "Position" );
	if ( childNode != NULL )
	{
		Position = childNode->getValue<const Char*>();
	}

	childNode = node->findChild( "Bone" );
	if ( childNode != NULL )
	{
		Bone = childNode->getValue<const Char*>();
	}

	childNode = node->findChild( "Range" );
	if ( childNode != NULL )
	{
		Range = childNode->getValue<float>();
	}

	childNode = node->findChild( "Color" );
	if ( childNode != NULL )
	{
		Color = childNode->getValue<const Char*>();
	}

	childNode = node->findChild( "AttenConst" );
	if ( childNode != NULL )
	{
		AttenConst = childNode->getValue<float>();
	}

	childNode = node->findChild( "AttenLinear" );
	if ( childNode != NULL )
	{
		AttenLinear = childNode->getValue<float>();
	}

	childNode = node->findChild( "AttenQuad" );
	if ( childNode != NULL )
	{
		AttenQuad = childNode->getValue<float>();
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void Light::write( XmlNode* node ) const
{
	assert( node != NULL );

	node->clearChild();
	node->clearAttribute();

	XmlNode* childNode = NULL;
	XmlAttribute* attribute = NULL;

	if ( Position != "" )
	{
		childNode = node->addChild( "Position" );
		childNode->setValue( Position );
	}

	if ( Bone != "" )
	{
		childNode = node->addChild( "Bone" );
		childNode->setValue( Bone );
	}

	if ( Range != 0.0f )
	{
		childNode = node->addChild( "Range" );
		childNode->setValue<float>( Range );
	}

	if ( Color != "" )
	{
		childNode = node->addChild( "Color" );
		childNode->setValue( Color );
	}

	if ( AttenConst != 0.0f )
	{
		childNode = node->addChild( "AttenConst" );
		childNode->setValue<float>( AttenConst );
	}

	if ( AttenLinear != 0.0f )
	{
		childNode = node->addChild( "AttenLinear" );
		childNode->setValue<float>( AttenLinear );
	}

	if ( AttenQuad != 0.0f )
	{
		childNode = node->addChild( "AttenQuad" );
		childNode->setValue<float>( AttenQuad );
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void Window::read( const XmlNode* node )
{
	assert( node != NULL );

	NodeIterator iter;
	const XmlNode* childNode = NULL;
	const XmlAttribute* attribute = NULL;

	attribute = node->findAttribute( "Type" );
	if ( attribute != NULL )
	{
		Type = attribute->getValue<const Char*>();
	}

	attribute = node->findAttribute( "Name" );
	if ( attribute != NULL )
	{
		Name = attribute->getValue<const Char*>();
	}

	childNode = node->findFirstChild( "Property", iter );
	while ( childNode != NULL )
	{
		Properties.resize( Properties.size() + 1 );
		Properties.back().read( childNode );
		childNode = node->findNextChild( "Property", iter );
	}

	childNode = node->findFirstChild( "Window", iter );
	while ( childNode != NULL )
	{
		Windows.resize( Windows.size() + 1 );
		Windows.back().read( childNode );
		childNode = node->findNextChild( "Window", iter );
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void Window::write( XmlNode* node ) const
{
	assert( node != NULL );

	node->clearChild();
	node->clearAttribute();

	XmlNode* childNode = NULL;
	XmlAttribute* attribute = NULL;

	if ( Type != "" )
	{
		attribute = node->addAttribute( "Type", Type.c_str() );
	}

	if ( Name != "" )
	{
		attribute = node->addAttribute( "Name", Name.c_str() );
	}

	for ( std::vector<Property>::const_iterator iter = Properties.begin();
		  iter != Properties.end();
		  ++iter )
	{
		const Property& obj = *iter;
		childNode = node->addChild( "Property" );
		obj.write( childNode );
	}

	for ( std::vector<Window>::const_iterator iter = Windows.begin();
		  iter != Windows.end();
		  ++iter )
	{
		const Window& obj = *iter;
		childNode = node->addChild( "Window" );
		obj.write( childNode );
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void Property::read( const XmlNode* node )
{
	assert( node != NULL );

	NodeIterator iter;
	const XmlNode* childNode = NULL;
	const XmlAttribute* attribute = NULL;

	attribute = node->findAttribute( "Name" );
	if ( attribute != NULL )
	{
		Name = attribute->getValue<const Char*>();
	}

	attribute = node->findAttribute( "Value" );
	if ( attribute != NULL )
	{
		Value = attribute->getValue<const Char*>();
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void Property::write( XmlNode* node ) const
{
	assert( node != NULL );

	node->clearChild();
	node->clearAttribute();

	XmlNode* childNode = NULL;
	XmlAttribute* attribute = NULL;

	if ( Name != "" )
	{
		attribute = node->addAttribute( "Name", Name.c_str() );
	}

	if ( Value != "" )
	{
		attribute = node->addAttribute( "Value", Value.c_str() );
	}
}

}
